/******************************************************
 *
 *
 *
 ******************************************************/

#ifndef	_SRLFS_H_
#define _SRLFS_H_

/* physical page info */
typedef	struct _page_attr
{
	unsigned char flag;			// valid or invalid, file or directory or partition info page
	unsigned char reserved;		// reserved
	unsigned short eccvalue;	// ECC value of this page, 16 bit, so page size must <= 2KB
	unsigned int reserved1;		// reserved1
	unsigned int next_page;		// next page in the same file, 0 means this is the last page
	unsigned int prev_page;		// previous page in the same file, 0 means this is file info page
}page_info;

/* file time structure */
typedef	struct _file_time_info
{
	unsigned short	year;
	unsigned char	month;
	unsigned char	day;
	unsigned char	hour;
	unsigned char	min;
	unsigned char	sec;
	unsigned char	flag;		// indicate time flag.exp: create time, modify time, access time.
}file_time_info;

/* file info */
typedef struct _file_info
{
	unsigned char	type;		// get this first.speed up^_^
	unsigned char	flags;		// indicate whether system or hide...
	unsigned char	reserved1;	// reserved
	unsigned char	reserved;	// reserved

	union{
		unsigned int	start_page_addr;		// the first data page address of this file
		unsigned int	first_file_page_addr;	// the first file page address of this directory
	}first_page_addr;

	unsigned int	parent;		// parent node physical address
	/* file descriptor */
	unsigned int	filesize;	// file size if this describe a file
	unsigned int	pagecount;	// page count of file if this describe a file
	unsigned int	check;		// file check value
	unsigned int	file_prev;	// previous file info page address in the same direcotry
	unsigned int	file_next;	// next file info page address in the same directory

	file_time_info	create_time;
	file_time_info	modify_time;
	file_time_info	access_time;
	
	unsigned char	name[_FILE_NAME_MAX_LENGTH_];
}file_info;

/* driver info */
typedef	struct _partition_info
{
	unsigned char valid_flag;	// partition valid flag,0 means unsable, not formated
	unsigned char reserved;		// reserved. reside structure in 4Byte
	unsigned short part_id;		// C,D,E­ UNICODE!
	unsigned char name[12];		// partition name
	unsigned int  pagecount;	// all page count in this partition
	unsigned int  firstfree;	// first free page physical address
	unsigned int  freecount;	// free page count in this partition
	unsigned int  invalidcount;	// invalid block count in this partition  
}partition_info;

/* root info */
typedef	struct _root_info
{
	unsigned char	magic[10];		// "SRLFS"
	unsigned short	part_count;		// count of drivers of current file system
	unsigned int	block_count;	// block count of all in current file system
	unsigned int	free_block;		// free block count in current file system
	unsigned int	invalid_count;	// invalid block count in current file system
	unsigned int	free_page;		// free page count in current file system
	partition_info	part_info[_SRLFS_ROOT_DRIVER_MAX_COUNT_];
}root_info;

/* file handle */
typedef	int	FHANDLE;

/* file descriptor */
typedef	struct _file_descriptor
{
	unsigned int filepage_address;	/* file information page address */
	unsigned int datapage_address;	/* file first data page address, we add this just for speed up */
	long long	 current_position;	/* current internal pointer in file */
	unsigned char openflag;			/* file open flag: create, readonly, writeonly and readwrite */
	unsigned char state;			/* file current state: reading, writring, or idal */
	unsigned short ownerprocess;	/* reserved1 */
}file_descriptor;

#endif /* _SRLFS_H_ */
